package com.yingsheng.bi.hks.basic.utils;

import com.yingsheng.bi.hks.basic.PUser;
import com.yingsheng.bi.hks.basic.ReqContext;
import com.yingsheng.bi.hks.repository.redis.SubjectRedisService;
import org.springframework.stereotype.Component;

@Component
public class Subject {

    private static SubjectRedisService redis;

    public Subject(SubjectRedisService subjectRedisService) {
        redis = subjectRedisService;
    }

    public static PUser get() {
        return redis.getUser(ReqContext.get().getIdentity());
    }

    public static void set(PUser user) {
        String identity = JwtUtils.identity(user.getChannelId(), user.getId());
        redis.setUser(identity, user);
    }

    public static void del() {
        redis.delUser(ReqContext.get().getIdentity());
    }


}
